﻿#include "ws_io_interface.h"

WsIoInterface::WsIoInterface()
{
	//nd_ = nullptr;
	//qRegisterMetaType<json>("json");
}

//void WsIoInterface::SetNodeDemo(NodeDemo * jm)
//{
//	nd_ = jm;
//}




bool WsIoInterface::isResDataReady()
{
	WsIoInterface::slock.lock();
	bool ret = (sendcache.size() > 0);
	WsIoInterface::slock.unlock();
	return ret;
}

std::string WsIoInterface::getResData()
{
	WsIoInterface::slock.lock();
	std::string d = sendcache.front();
	sendcache.pop();
	WsIoInterface::slock.unlock();
	return d;
}

void WsIoInterface::sendResData(uint8_t *res,int len)
{
	WsIoInterface::slock.lock();
	std::string gen;
	gen.assign((char*)res, len);
	sendcache.push(gen);
	WsIoInterface::slock.unlock();
}

bool WsIoInterface::isRawDataReady()
{
	WsIoInterface::rlock.lock();
	bool ret = (recvcache.size() > 0);
	WsIoInterface::rlock.unlock();
	return ret;
}

std::string WsIoInterface::getRawData()
{
	WsIoInterface::rlock.lock();
	std::string d = recvcache.front();
	recvcache.pop();
	WsIoInterface::rlock.unlock();
	return d;
}

void WsIoInterface::recvRawData(const std::string & pkg)
{
	WsIoInterface::rlock.lock();
	recvcache.push(pkg);
	WsIoInterface::rlock.unlock();
}